<?php

require_once('../include/GeneralTop.php');
require('../include/class/db.php');
require('../include/class/pagination.php');

if (!$content_admin) {
	die('<div style="text-align:center">Permission denied...</div>');
}

$db = new db;

if ((isset($_GET['Id'])) && ($_GET['Id'] != "" && $_GET['action'] == 'del')) {
    $deleteSQL = sprintf("DELETE FROM petmanual WHERE Id=%s",
                       GetSQLValueString($_GET['Id'], "int"));

    $db->query($deleteSQL);
}

include('AdminPanel.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
</head>

<body>
<table width="60%" border="0" align="center" cellpadding="5" cellspacing="0" class="table_border_grey" style="margin-top:10px;">
  <tr>
    <td colspan="5">
	  <form action="<?php echo $_SERVER['PHP_SELF']?>" method="GET">
	  搜索养育指南： <input type="text" name="kw" size="20">
	  <input type="submit" name="submit" id="submit" value=" 按标题搜索 ">
	  </form>
	</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td width="160">标题</td>
    <td width="80">分类</td>
    <td width="500">内容</td>
  </tr>
    <?php
    if(isset($_GET['submit']) && $_GET['kw'] != '') {
		$sql = "SELECT *, SUBSTRING(mal_info,1,55) AS info FROM petmanual where mal_title like '%".$_GET['kw']."%' order by Id DESC";
	}
	else {
    	$sql = "SELECT *, SUBSTRING(mal_info,1,55) AS info FROM petmanual order by Id DESC";
	}
	$res = $db->query($sql);
	$num = $db->num($res);
	if($num > 0) {
		$pagination = new Pagination($num, PAGICATION_RECORD_COUNT_NEWS, $_GET['page'], PAGINATION_DELTA);
		$sql = $sql." limit ".$pagination->begin.",".$pagination->end;
		$res = $db->query($sql);
		while($row = $db->fetch($res)) {
    ?>
    <tr>
      
      <td> 
      	<label>
          <input type="button" name="button" id="button" value="Delete" onclick="if(confirm('Are you sure to delete this?')){window.location.href='<?php echo $_SERVER['PHP_SELF']?>?action=del&Id=<?php echo $row['Id']; ?>'}"/>
        </label>
      </td>
      <td><label><a href="EditPetManual.php?Id=<?php echo $row['Id'] ?>">Edit...
        </a>
      </label></td>
      <td><a href="PetManualinfo.php?Id=<?php echo $row['Id']; ?>"><?php echo $row['mal_title']; ?></a></td>
      <td><?php echo getManualType($row['mal_class']); ?>&nbsp; </td>
      <td><?php echo $row['info']; ?>...&nbsp; </td>
    </tr>
    <?php
		}
	}
	?>
	<tr>
    <td colspan="5">
	    <?php
		if($num > PAGICATION_RECORD_COUNT_NEWS) {
			echo $pagination->paginationString;
		}
		?>
	</td>
  </tr>
</table>
<br />
</body>
</html>